package com.leenmvc.core.config;

import com.leenmvc.core.config.intercept.GlobalIntercept;
import com.leenmvc.core.config.intercept.LogIntercept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootConfiguration
public class IntercetporConfig implements WebMvcConfigurer {

    @Autowired
    private GlobalIntercept globalIntercept;

    @Autowired
    LogIntercept logIntercept;

    /**
     * 配置拦截器URL路径
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(globalIntercept).addPathPatterns("/**").excludePathPatterns("/swagger-ui.html");
        registry.addInterceptor(logIntercept).addPathPatterns("/**");
    }
    /**
     * 配置静态访问资源
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }

}